/*	
 *  -- ************************************************************
 -- Author		:	PUY
 -- Create date	:	-
 -- Update date	:	PUY
 -- Update By	:   29-07-2011
 -- Description	:	
 -- ************************************************************
 */
package smartq.DB;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Types;

public class Table {

	//-------------------- Variable -------------------------
    private String OID,
    		UsrOpt,
    		IsActive,
    		IsDeleted,
    		TableName,
    		TableStatus,
    		TableNumber,
    		TableTime;

	 public Table() {
		 TableName = TableStatus = TableNumber = TableTime = "";
	 }	
    public Table (
            String OID,
            String UsrOpt,
            String IsActive,
            String IsDeleted,
            String TableName,
            String TableStatus,
            String TableNumber,
            String TableTime
            )
    
   {
        this.OID 					= OID;
        this.UsrOpt 				= UsrOpt;
        this.IsActive 				= IsActive;
        this.IsDeleted 				= IsDeleted;
        this.TableName 				= TableName;
        this.TableStatus 			= TableStatus;
        this.TableNumber 			= TableNumber;
        this.TableTime 				= TableTime;
        
    }
    
    Connect con = new Connect(); 
    Connection conn = con.Connect();
    ResultSet rs = null;
    
    // -------------------- GET-SET -------------------------


	public String getUsrOpt() {
		return UsrOpt;
	}

	public String getTableTime() {
		return TableTime;
	}
	public void setTableTime(String tableTime) {
		TableTime = tableTime;
	}
	public String getTableName() {
		return TableName;
	}
	public void setTableName(String tableName) {
		TableName = tableName;
	}
	public String getTableStatus() {
		return TableStatus;
	}
	public void setTableStatus(String tableStatus) {
		TableStatus = tableStatus;
	}
	public String getTableNumber() {
		return TableNumber;
	}
	public void setTableNumber(String tableNumber) {
		TableNumber = tableNumber;
	}
	public void setUsrOpt(String usrOpt) {
		UsrOpt = usrOpt;
	}

	
    public String getOID() {
		return OID;
	}

	public void setOID(String oID) {
		OID = oID;
	}

	public String getIsActive() {
		return IsActive;
	}

	public void setIsActive(String isActive) {
		IsActive = isActive;
	}

	public String getIsDeleted() {
		return IsDeleted;
	}

	public void setIsDeleted(String isDeleted) {
		IsDeleted = isDeleted;
	}

	

	//-------------------- SQL ------------------------
    public ResultSet selectTable(String Status) throws Exception {
    	String StrSql = "SELECT [OID] "
                + ",[LastModified]"
                + ",[ModifiedDate]"
                + ",[ModifiedTime]"
                + ",[ModifiedBy]"
                + ",[UserModified]"
                + ",[CreatedDate]"
                + ",[CreatDate]"
                + ",[CreatTime]"
                + ",[CreatedBy]"
                + ",[UserCreate]"
                + ",[IsActive]"
                + ",[IsDeleted]"
                
                + ",[TableName] "
                + ",[TableStatus] "
                + ",[TableNumber] "
                + ",[TableTime] "
                
                + "FROM [Project_NFC].[dbo].[udfTable]() "
                
                + "WHERE [IsDeleted]='0' "; 
    	
    	if (!Status.equals("")) {
            StrSql += " AND [TableStatus] LIKE '" + Status + "%' "
            		+ "OR [TableName] LIKE '%" + Status + "%' " ;
        }
//    	
//    	if (!Status.equals("")) {
//            StrSql += "AND [TableStatus] LIKE '%" + Status + "%' ";
//        }
    	return con.selectData(StrSql);
        //return sqlsel.getReSultSQL(StrSql);
    }

  

    public String OperationData(String OperationType) throws Exception {
        try {
        	conn = con.Connect();
                java.sql.CallableStatement cstmt = conn.prepareCall("{call stpTableManagement(?,?,?,?,? ,?,?,?,?,?)}");
                
                cstmt.setString(1, OperationType);
                cstmt.setString(2, getOID());
                cstmt.setString(3, getUsrOpt());
                cstmt.setString(4, getIsActive());
                cstmt.setString(5, getIsDeleted());

                cstmt.setString(6, getTableName());
                cstmt.setString(7, getTableStatus());
                cstmt.setString(8, getTableNumber());
                cstmt.setString(9, getTableTime());
                
                cstmt.registerOutParameter(10, Types.VARCHAR);
                cstmt.execute();
                return cstmt.getString(10);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (conn != null) {
                conn.close();
            }
        }
        return null;
    }
}
